//
//  ViewController+Option.swift
//  YS
//
//  Created by 元穗 on 2017/5/19.
//  Copyright © 2017年 yuansui. All rights reserved.
//

/// 刷新方式

public enum RefreshWay {
    case Dialog, Embed, Swipe
}

/// 刷新操作

public protocol RefreshOpt {
    /// 以设定的默认方式刷新
    /// - parameter way: 刷新的方式
    func refresh(way: RefreshWay);

    /// dialog式刷新
    func dialogRefresh();

    /// 内嵌式刷新
    func embedRefresh();

    /// 下拉刷新
    func swipeRefresh();
}

/// 其他操作

extension ViewConEx {
    public func presentViewCon(storyboard name: String) {
        let sb = UIStoryboard.init(name: name, bundle: nil);
        present(sb.instantiateInitialViewController()!, animated: true);
    }

    public func presentViewCon(_ viewCon: UIViewController) {
        present(viewCon, animated: true);
    }

    public func pushViewCon(storyboard name: String) {
        let sb = UIStoryboard.init(name: name, bundle: nil);
        self.navigationController?.pushViewController(sb.instantiateInitialViewController()!, animated: true);
    }

    public func pushViewCon(_ viewCon: UIViewController) {
        self.navigationController?.pushViewController(viewCon, animated: true);
    }
    
    public func popViewCon() {
        self.navigationController?.popViewController(animated:true);
    }
    
    public func popToRootViewCon() {
        self.navigationController?.popToViewController((self.navigationController?.viewControllers[0])!, animated: true)
        
    }
    
    public func popToViewCon(_ viewCon: UIViewController) {
        DispatchQueue.main.async(execute: {
            self.navigationController?.popToViewController(viewCon, animated: true)
        })
    }
    
    public func showToast(_ text: String) {
        Log.d("显示了一个toast" + text);
    }
}






